<template>
  <el-dialog v-model="dialog" title="添加管理员" width="500">
    <el-form :model="form">
      <el-form-item label="账号" :label-width="formLabelWidth">
        <el-input v-model="form.adminname" autocomplete="off" />
      </el-form-item>
      <el-form-item label="密码" :label-width="formLabelWidth">
        <el-input v-model="form.password" autocomplete="off" />
      </el-form-item>
      <!-- <el-form-item label="角色" :label-width="formLabelWidth">
        <el-input v-model="form.role" autocomplete="off" />
      </el-form-item> -->
      <el-form-item label="角色">
      <el-select v-model="form.role">
        <el-option value="1" label="超级管理员"></el-option>
        <el-option value="2" label="轮播图维护人员"></el-option>
        <el-option value="3" label="商品维护人员"></el-option>
        <el-option value="4" label="售后人员"></el-option>
      </el-select>
    </el-form-item>
      <div>
      <el-tree
        ref="treeRef"
        style="max-width: 600px"
        :data="data"
        show-checkbox
        default-expand-all
        node-key="id"
        highlight-current
        :props="defaultProps"
      />
    </div>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="FormVisible">取消</el-button>
        <el-button type="primary" @click="dialogFormVisible">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
  
  <script lang="ts" setup>
import { reactive, ref, defineEmits ,} from "vue";
import type { IOper } from "@/MyType";
import { Addmanagementpersonnelapi} from "@/api/management";
import { ElMessage ,ElTree} from "element-plus";
import data from "./menudData";
const emit = defineEmits<{
  (e: "dialog", isRefresh: boolean): void;
}>();
const dialog = ref(true);
const formLabelWidth = "66px";
const form = reactive<Array<IOper>>({
  adminname: "",
  password: "",
  role: "",
  checkedKeys:""
  // date1: "",
  // date2: "",
  // delivery: false,
  // type: [],
  // resource: "",
});
// 取消按钮  
// const cancelFn = () => {
//   emit("closeWin", false);
// };
const FormVisible = ()=>{
  emit("dialog");
  // dialog.value = false;
}
const treeRef = ref<InstanceType<typeof ElTree>>();
const dialogFormVisible = async ()=>{
  form.checkedKeys = JSON.stringify(treeRef.value!.getHalfCheckedKeys().concat( treeRef.value!.getCheckedKeys(false)));
  const res = await Addmanagementpersonnelapi(form).then((res)=>{
    if (res.data.code === "200") {
    ElMessage.success("添加成功了！");
    form.adminname = ""
    form.password = ""
    form.role = ""
      emit("dialog",true)
    }
    })
  // clearbanner();
}



// 添加 管理员信息
// Personne
// const 

// const handleEdit =async ()=>{
//   const res = await Addmanagementpersonnelapi()
// } 
</script>
  

<style>
</style>